import util

# print(util.checkSum('aa55010001000200000000000000000000000000000000000301'))
# pkgp,pkg = util.makeCommandPackage(1)
# print(pkg)

# print(util.CommandPackage(packageString = "AA55000001000000000000000000000000000000000000000001").getPackageString())
# print(util.ResponsePackage(packageString = "55AA010001000200000000000000000000000000000000000301").getPackageString())
# print(util.CommandDataPackage(packageString = "AA55000001000000000000000000000000000000000000000001").getPackageString())
# print(util.ResponseDataPackage(packageString = "A55A010004001F00000053454F4E5F47445F4650433130323028323030306670292056312E30002B08").getPackageString())
                                              # A55A010004001F00000053454F4E5F47445F4650433130323028323030306670292056312E30002B08






# import redis

# db = redis.StrictRedis(host="localhost", port=6379, db=0, password="cosmo")

# db.set("hehe", "haha")
# print(db.get("hehe"))

from util import Session

session = Session()
session.connect()

# def getTemplate(tplId):
# 	if session.loadChar(templateId = tplId):
# 		print("load char success")
# 	else:
# 		raise Exception("load char failed")
# 	data = session.uploadChar()
# 	print("char data: \r\n", data)
# 	# if session.downloadChar(data = data):
# 	# 	print("download char success")
# 	# else:
# 	# 	raise Exception("download char failed")
# 	print("\r\n")

# getTemplate(1)
# getTemplate(2)
# # getTemplate(3)
# # getTemplate(4)

while True:
	if not session.detectFinger(): continue
	print("")
	if session.saveImage():
		if session.generateTemplate():
			data = session.uploadChar()
			print(data)
		else:
			print("Error generating template")
	else:
		print("Error saving image")
	while True:
		if not session.detectFinger(): break






